using System;
using Microsoft.SharePoint.Client;

namespace SharePoint.Security.ContentScanner.Engine.Analyzers
{
    public static class Extensions
    {
        public static Uri GetServerUrl(this Uri url)
        {
            return new Uri(string.Format("{0}://{1}{2}", url.Scheme, url.Host, (url.Port == 80 || url.Port == 443) ? "" : string.Format(":{0}", url.Port)));
        }

        public static string GetFileUrl(this Microsoft.SharePoint.Client.File file)
        {
            var url = new Uri(file.Context.Url.ToLower());
            return string.Format("{0}{1}", url.GetServerUrl(), file.ServerRelativeUrl);
        }

        public static string GetUrl(this Web webApp)
        {
            var url = new Uri(webApp.Context.Url.ToLower());
            return string.Format("{0}{1}", url.GetServerUrl(), webApp.ServerRelativeUrl);
        }

    }
}